import React, { FC, useEffect } from "react";
import { QuestionSliderPropsType } from "./interface";
import { Form, Input, InputNumber } from "antd";

const PropComponent: FC<QuestionSliderPropsType> = (
  props: QuestionSliderPropsType
) => {
  const { title, noText, yesText, curNum, onChange, disabled } = props;
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue({ title, yesText, noText, curNum });
  }, [title, yesText, noText, curNum]);
  function handleValueChange() {
    if (onChange == null) return;
    onChange(form.getFieldsValue());
  }
  return (
    <Form
      layout="vertical"
      initialValues={{ title, noText, yesText, curNum }}
      disabled={disabled}
      form={form}
      onValuesChange={handleValueChange}
      style={{ maxWidth: 250 }}
    >
      <Form.Item
        label="标题"
        name="title"
        rules={[{ required: true, message: "请输入标题" }]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="不满意"
        name="noText"
        rules={[{ required: true, message: "请输入文字" }]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="满意"
        name="yesText"
        rules={[{ required: true, message: "请输入文字" }]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="当前数字"
        name="curNum"
        rules={[{ required: true, message: "请输入数字" }]}
      >
        <InputNumber min={0} max={100} />
      </Form.Item>
    </Form>
  );
};

export default PropComponent;
